#聊天室首页测试用例
from selenium.webdriver.common.by import By

from common.Utils import ChatDriver
class ChatList():
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://127.0.0.1:8080/client.html"
        self.driver = ChatDriver.driver
        self.driver.get(self.url)

    #测试首页（登录）
    def ListTestByLogin(self):
        #测试用户名是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.client-container > div > div.left > div.user")
        #测试搜索框是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.client-container > div > div.left > div.search")
        #测试会话列表标签和会话列表是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.client-container > div > div.left > div.tab > div.tab-session")
        #测试好友列表标签和好友列表是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.client-container > div > div.left > div.tab > div.tab-friend")
        #测试会话标题是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.client-container > div > div.right > div.title")
        #测试消息区是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.client-container > div > div.right > div.message-show")
        #测试消息编辑区是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.client-container > div > div.right > textarea")
        #测试发送按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.client-container > div > div.right > div.ctrl > button")

        ChatDriver.getScreenshot()

    #测试首页（未登录）
    def ListTestByUnlogin(self):
        alert = self.driver.switch_to.alert
        print(alert.text)
        alert.accept()